package com.comp3111.happymeal;

import com.configuration.Owner;

import android.app.Activity;
import android.app.ProgressDialog;
import android.content.Intent;
import android.view.Menu;
import android.os.Handler;
import android.support.v4.widget.DrawerLayout;
import android.widget.*;
import android.view.View;

public class NavigationDrawerActivity extends Activity {
	//public String[] drawerTitle = {"Discover", "Restaruant", "Food", "Profile", "Following", "Search","MealCommentTesting"};
	public String[] drawerTitle = {"Discover", "Restaruant","My Profile", "Following", "Search"};
	
	public DrawerLayout drawerLayout;
	public ListView drawerList;
	public ProgressDialog dialog;
	
	public void createDrawer() {
		dialog = new ProgressDialog(NavigationDrawerActivity.this);
        dialog.setMessage("Loading...");
        
		drawerLayout = (DrawerLayout) findViewById(R.id.drawer_layout);
		drawerList = (ListView) findViewById(R.id.left_drawer);
		drawerList.setAdapter(new ArrayAdapter<String>(this, R.layout.drawer_list_item, drawerTitle));
		drawerList.setOnItemClickListener(new ListView.OnItemClickListener() {
		    @Override
		    public void onItemClick(AdapterView parent, View view, int position, long id) {
		        selectItem(position);
		    }
		});
	}
	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.main, menu);
		return true;
	}
	public void selectItem(final int position) {
		drawerList.setItemChecked(position, true);
		setTitle(drawerTitle[position]);
	    drawerLayout.closeDrawer(drawerList);
	    
	    new Handler().postDelayed(new Runnable() {
	        @Override
	        public void run() {
	    
	    if(position == 0) {
	    	Intent intent = new Intent(getApplication(), DiscoverPageActivity.class);
	    	intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		    startActivity(intent);
		    //finish();
	    }
	    if(position == 1) {
	    	Intent intent = new Intent(getApplication(), RestaurantListActivity.class);
	    	intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
		    startActivity(intent);
		    //finish();
	    }
	    if(position == 2) {
	    	Intent intent = new Intent(getApplication(), UserProfileActivity.class);
	    	intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	    	intent.putExtra("USERID",Integer.toString(Owner.id));
		    startActivity(intent);
		    //finish();
	    }
	    
	    if(position == 3) {
	    	Intent intent = new Intent(getApplication(), FollowingPageActivity.class);
	    	intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	    	startActivity(intent);
	    	//finish();
	    }
	    if(position == 4) {
	    	Intent intent = new Intent(getApplication(), SearchActivity.class);
	    	intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP);
	    	startActivity(intent);
	    	//finish();
	    }
	    
	        }
	    }, 250);
	    
	}
}